<template>
    <div class="commodityEdit">
        <h2 class="my-big-font">编辑商品</h2>
        <div class="commodityEdit-content">
            <ul>
                <li class="input-box">
                    <span class="title">产品编号</span>
                    <span>{{VipShopEntity.goodsId}}</span>
                </li>
<!--                <li class="input-box">
                    <span class="title">品牌</span>
                    <span>{{VipShopEntity.pname}}</span>
                </li>-->
                <li class="input-box">
                    <span class="title">产品名称</span>
                    <span>{{VipShopEntity.name}}</span>
                </li>
<!--                <li class="input-box">
                    <span class="title">分类</span>
                    <span>{{VipShopEntity.categoryName}}</span>
                </li>
                <li class="input-box">
                    <span class="title">规格</span>
                    <span>{{VipShopEntity.specsName}}</span>
                </li>-->
                <li class="input-box">
                    <span class="title">原价(元)</span>
                    <span>{{VipShopEntity.originalCost}}</span>
                </li>
                <li class="input-box">
                    <span class="title">供货价(元)</span>
                    <span>{{VipShopEntity.supplyCost}}</span>
                </li>
                <li class="input-box">
                    <span class="title">安卓现价(元)</span>
                    <input class="content-inp" type="text" v-model="goodsparvalue">
                </li>
                 <li class="input-box">
                    <span class="title">苹果现价(元)</span>
                    <input class="content-inp" type="text" v-model="apGoodsparvalue">
                </li>
                 <li class="input-box">
                    <span class="title">苹果id</span>
                    <input class="content-inp" type="text" v-model="apProductCode">
                </li>
                <li class="input-box">
                    <span class="title">保护价(元)</span>
                    <input class="content-inp" type="text" v-model="protectCost">
                </li>
                <li class="input-box">
                    <span class="title">上架时间</span>
                    <el-date-picker  v-model="groundTime"  type="datetime"  placeholder="选择上架日期"  :picker-options="pickerOptions"></el-date-picker>
                </li>
            </ul>
        </div>
        <div class="btn-box">
            <span class="my-btn btn1" @click="submitClick">保存</span>
            <span class="my-btn btn2" @click="cancel">取消</span>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            id:'',
            uid:'',
            goodsparvalue:'',//现价
            apGoodsparvalue:'',//
            apProductCode:'',
            protectCost:'',//保护价
            groundTime:'',//上架时间
            VipShopEntity:{
                categoryId: '',
                //categoryName: '',
                createTime: '',
                explains: null,
                file: null,
                goodsId: '',
                goodsparvalue: '',
                apGoodsparvalue:'',
                apProductCode:'',
                groundTime: '',
                id: '',
                name: '',
                originalCost: '',
                pid: '',
                //pname: '',
                protectCost: '',
                purchasePrice: '',
                //saveMoney: '',
                specsId: '',
                //specsName: '',
                state: '',
                supplyCost: '',
                //totalSales: '',
                underTime: '',
            },
            pickerOptions:{
                disabledDate(time){
                    return time.getTime() < (Date.now()-(24 * 60 * 60 * 1000));
                }
            },
        }
    },
    mounted(){
        this.id=this.$route.query.id
        this.uid=this.$route.query.uid
        this.getvipShop()
    },
    methods:{
        //获取商品基本信息
        getvipShop(){
             this.axios.get("/recharge/sys/vipshop/info?id="+this.id).then(result=>{
                this.VipShopEntity=result.data.data
                this.goodsparvalue=this.VipShopEntity.goodsparvalue
                this.apGoodsparvalue=this.VipShopEntity.apGoodsparvalue
                this.apProductCode=this.VipShopEntity.apProductCode
                this.protectCost=this.VipShopEntity.protectCost
                this.groundTime=this.format(this.VipShopEntity.groundTime)
            })
        },
        //提交
        submitClick(){
            // this.VipShopEntity.userid= this.uid*1
            this.VipShopEntity.goodsparvalue= this.goodsparvalue
            this.VipShopEntity.apGoodsparvalue= this.apGoodsparvalue
            this.VipShopEntity.apProductCode= this.apProductCode
            this.VipShopEntity.protectCost= this.protectCost
            this.VipShopEntity.groundTime= (new Date(this.groundTime)).getTime() / 1000;
            this.axios.post("/recharge/sys/vipshop/update?userid="+this.uid*1,this.VipShopEntity).then(result=>{
                this.$router.push('/index/management')
            })
        },
        //取消
        cancel(){
            this.$router.push('/index/management')
        },
        //处理时间戳
        format(shijianchuo) {
            if(shijianchuo){
                var time = new Date(parseInt(shijianchuo)*1000);
                var y = time.getFullYear();
                var m = time.getMonth() + 1;
                var d = time.getDate();
                var h = time.getHours();
                var f = time.getMinutes();
                var s = time.getSeconds();
                //想要什么格式可以自己改
                // return y + '-' + this.add0(m) + '-' + this.add0(d) +" "+ this.add0(h)+':'+this.add0(f)+':'+this.add0(s);
                return y + '-' + m + '-' + d +" "+ this.add0(h)+':'+this.add0(f)+':'+this.add0(s);
            }
        },
        //小于10的时候，前边加0（08：08：12）
        add0(m) {
            return m < 10 ? '0' + m : m
        },
    }
}
</script>

<style scoped>
.commodityEdit{
    padding: 30px 82px 50px 30px;
    background: #fff;
    margin: 10px 0 0 10px;
    color: #333333;
    min-height: calc(100vh - 96px);
}
.commodityEdit h2{
    padding-top: 0;
}
/* 内容 */
.commodityEdit-content{
    margin-top: 30px;
    padding-bottom: 60px;
    border-bottom:1.5px solid #ccc ;
}
.input-box{
    position: relative;
    margin-bottom: 20px;
}
.input-box .title{
    width: 97px;
    display: inline-block;
}
/* input框 */
.input-box input{
    min-width: 220px;
    height: 35px;
    border-radius: 4px;
    padding: 8px;
}
/* 提示信息 */
.prompt{
    color: red;
    position: absolute;
    bottom: 0;
    left: 92px;
    font-size: 15px;
}
.commodityEdit .btn-box{
    padding: 30px 40px;
}
.commodityEdit .btn-box span{
    width: 110px;
    height: 35px;
    line-height: 35px;
    border-radius: 5px;
    border: 0;
    margin-right: 40px;
}
.commodityEdit .btn-box .btn2{
    background: #ddd;
    color: #fff;
}
</style>